package users;
import java.util.ArrayList;
import flex.messaging.MessageBroker;
import flex.messaging.messages.AsyncMessage;
import flex.messaging.util.UUIDUtils;

public class Userlist {
	private static ArrayList<String> userList;
	public Userlist() {
	if(userList == null) {
	userList = new ArrayList<String>();
	}
	}
	public void addUser(String newUser) {
	userList.add(newUser);
	sendUserlist();
	}

	public void removeUser() {
		userList.clear();
		sendUserlist();
	}
	public ArrayList<String> getUserlist(){
		return userList;
	}
	public void sendUserlist() {
		try {
		Thread.sleep(200);
		} catch (InterruptedException e) {
		e.printStackTrace();
		}
		MessageBroker msgBroker = MessageBroker.getMessageBroker(null);
		AsyncMessage msg = new AsyncMessage();
		msg.setDestination("myUserlistDest");
		msg.setClientId(UUIDUtils.createUUID());
		msg.setMessageId(UUIDUtils.createUUID());
		msg.setTimestamp(System.currentTimeMillis());
		msg.setBody(userList);
		msgBroker.routeMessageToService(msg, null);
	}
}
